# 导入neo4j驱动包
from neo4j import GraphDatabase

# 设置数据库连接的URI
uri = "bolt://localhost:7687"
# 设置认证信息（用户名和密码）
auth = ("neo4j", "12345678")
# 创建数据库驱动对象
driver = GraphDatabase.driver(uri, auth=auth)
with driver.session() as session:
    result = result = session.run(
        """
            MATCH (u:User) WHERE u.name CONTAINS '张' RETURN u.name
        """
    )
    print(result.data())
    result = session.run(
        """
            MATCH (u:User)-[:FRIEND]->(f:User)
            RETURN u.name, size(collect(f)) AS 朋友数
        """
    )
    print(result.data())
    result = session.run(
        """
            MERGE (u:User {name: '赵六'})
            ON CREATE SET u.created = date()
            ON MATCH SET u.lastLogin = date()
            RETURN u
        """
    )
    print(result.data())


